﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NMF.Transformations;
using NMF.Optimizations;
using NMF.Transformations.Core;

namespace NMF.Transformations.Optimizations
{
    public class OptimizationPattern : ITransformationPattern
    {
        private List<Func<OptimizationPatternContext, IObservableSource<IOptimizationModification>>> patterns = new List<Func<OptimizationPatternContext, IObservableSource<IOptimizationModification>>>();

        public IOptimizer Optimizer { get; set; }
        public IScenarioEvaluator Evaluator { get; set; }

        public ITransformationPatternContext CreatePattern(ITransformationContext context)
        {
            throw new NotImplementedException();
        }

        public class OptimizationPatternContext : Optimization, ITransformationPatternContext
        {
            public ITransformationContext Context { get; private set; }
            public OptimizationPattern Pattern { get; private set; }

            public void Finish()
            {
                Optimize(Pattern.Optimizer, Pattern.Evaluator);
            }

            public OptimizationPatternContext(ITransformationContext context, OptimizationPattern pattern)
            {
                if (context == null) throw new ArgumentNullException("context");
                if (pattern == null) throw new ArgumentNullException("pattern");

                Context = context;
                Pattern = pattern;

                foreach (var patt in pattern.patterns)
                {
                    AddPattern(patt(this));
                }
            }
        }
    }
}
